import 'package:get/get.dart';
import 'package:xinxuan/common/dialogs/message_dialog.dart';
import 'package:xinxuan/controllers/common_page_controller.dart';
import 'package:xinxuan/http/http_util_service.dart';
import 'package:xinxuan/router/app_routers.dart';
import 'package:xinxuan/vo/activity_acquisitions_vo.dart';
import 'package:xinxuan/vo/activity_step_vo.dart';

class ActivityPageController extends GetxController {

  final CommonPageController commonPageController = Get.find();

  var activityAcquisitionsVo = ActivityAcquisitionsVo(
    data: ActivityAcquisitionsData(status: 0, tips: '', isIdentified: 0, isPurchased: 0),
    meta: ActivityAcquisitionsMeta(
      steps: []
    )
  ).obs;

  var stepIndex = 0.obs;

  @override
  void onReady() {
    getActivityAcquisitions();
    super.onReady();
  }

  /// 活动状态
  getActivityAcquisitions({ bool loading = true }) async {
    ActivityAcquisitionsVo acquisitionsVo = await HttpUtilService.getActivityAcquisitions(loading: loading);
    activityAcquisitionsVo.value = acquisitionsVo;
    update();
  }


  /// 按步骤参与活动
  activityStep(int step) async {
    /// 如果是去认证按钮，并且是老用户的话，直接跳转认证页
    if (step == 2 && commonPageController.userData.value.isNew == 0) {
      Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}${AppRouters.AUTHENTICATION_PAGE}');
      return;
    }
    ActivityStepVo activityStepVo = await HttpUtilService.activityStep(step: step);
    Get.dialog(MessageDialog(
      message: activityStepVo.msg ?? '',
    ));
    getActivityAcquisitions();
    commonPageController.checkLogin(loading: false);
  }

}